using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DTO;

namespace DAO
{
    public class NhanVienDAO:DataProvider
    {
        public DataTable TimNhanVien(string username, string password)
        {
            string sql = "select * from NhanVien ";
            sql += " where username='" + username + "' and passwords='" + password + "'";
            DataTable dt = DocBang(sql);
            return dt;
        }
        public DataTable TraCuuNhanVien(string sql)
        {
            return DocBang(sql);
        }
        public void Them(NhanVienDTO nvdto)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.KetNoi();
            string str = "Insert into NhanVien(Ten, CMND, DiaChi, MaLoai, Username,Passwords) values (?, ?, ?, ?, ?, ?)";

            OleDbCommand cmd = new OleDbCommand(str, cn);

            cmd.Parameters.Add("@Ten", OleDbType.WChar);
            cmd.Parameters.Add("@CMND", OleDbType.Integer);
            cmd.Parameters.Add("@DiaChi", OleDbType.WChar);
            cmd.Parameters.Add("@MaLoai", OleDbType.Integer);
            cmd.Parameters.Add("@Username", OleDbType.WChar);
            cmd.Parameters.Add("@Passwords", OleDbType.WChar);

            cmd.Parameters["@Ten"].Value = nvdto.Ten;
            cmd.Parameters["@CMND"].Value = nvdto.CMND;
            cmd.Parameters["@DiaChi"].Value = nvdto.DiaChi;
            cmd.Parameters["@MaLoai"].Value = nvdto.MaLoai;
            cmd.Parameters["@Username"].Value = nvdto.UserName;
            cmd.Parameters["@Passwords"].Value = nvdto.Password;

            cmd.ExecuteNonQuery();

            cn.Close();
        }
        public void Sua(NhanVienDTO nvdto)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = KetNoi();
            string sql = "Update NhanVien Set Ten = ? , CMND = ? , DiaChi = ? , MaLoai = ? , Username = ? , Passwords = ?  Where Ma = ?";
            OleDbCommand cmd = new OleDbCommand(sql, cn);

            cmd.Parameters.Add("@Ten", OleDbType.WChar);
            cmd.Parameters.Add("@CMND", OleDbType.Integer);
            cmd.Parameters.Add("@DiaChi", OleDbType.WChar);
            cmd.Parameters.Add("@MaLoai", OleDbType.Integer);
            cmd.Parameters.Add("@Username", OleDbType.WChar);
            cmd.Parameters.Add("@Passwords", OleDbType.WChar);
            cmd.Parameters.Add("@Ma", OleDbType.Integer);

            cmd.Parameters["@Ten"].Value = nvdto.Ten;
            cmd.Parameters["@CMND"].Value = nvdto.CMND;
            cmd.Parameters["@DiaChi"].Value = nvdto.DiaChi;
            cmd.Parameters["@MaLoai"].Value = nvdto.MaLoai;
            cmd.Parameters["@Username"].Value = nvdto.UserName;
            cmd.Parameters["@Passwords"].Value = nvdto.Password;
            cmd.Parameters["@Ma"].Value = nvdto.Ma;

            cmd.ExecuteNonQuery();
            cn.Close();
        }
        public void Xoa(int manv)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = KetNoi();
            string sql = "Update NhanVien Set Xoa = ?  Where Ma = ?";
            OleDbCommand cmd = new OleDbCommand(sql, cn);

            cmd.Parameters.Add("@Xoa", OleDbType.Boolean);
            cmd.Parameters.Add("@Ma", OleDbType.Integer);

            cmd.Parameters["@Xoa"].Value = true;
            cmd.Parameters["@Ma"].Value = manv;

            cmd.ExecuteNonQuery();
            cn.Close();
        }
    }
}
